package com.hr.runnerbuddy;

import java.io.ByteArrayOutputStream;
import com.hr.runnerbuddy.database.DBAdapter;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Window;

public class Splash extends Activity {
	private final int SPLASH_DISPLAY_LENGHT = 2000;
	private DBAdapter dbAdapter;
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.splash);
		
		new Handler().postDelayed(new Runnable(){
		         public void run() {
		                /* Create an Intent that will start the Menu-Activity. */
		                Intent mainIntent = new Intent(Splash.this,Hoofdmenu.class);
		                Splash.this.startActivity(mainIntent);
		                Splash.this.finish();
		         }
		}, SPLASH_DISPLAY_LENGHT);
		Log.d("HELP","context "+getApplicationContext());
		dbAdapter = new DBAdapter(getApplicationContext());
		dbAdapter.open();
		if(dbAdapter.getParcourpunten(0).size()<=0){
	    	//bitmap to byte[] conversie
	    	Bitmap bitmap = BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.route_rotterdam2);
	        ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
	        bitmap.compress(CompressFormat.PNG, 0 /*ignored for PNG*/, bos); 
	        byte[] bitmapdata = bos.toByteArray();
	        //Log.d("whoops", "Byte[] bitmap image lengte "+bitmapdata.length);
	        
	        //if bitmapdata is the byte array then getting bitmap goes like this
//	        Bitmap bitmap2 = BitmapFactory.decodeByteArray(bitmapdata , 0, bitmapdata .length);
//	        
//	        Toast ImageToast = new Toast(getBaseContext());
//	        LinearLayout toastLayout = new LinearLayout(getBaseContext());
//	        toastLayout.setOrientation(LinearLayout.HORIZONTAL);
//	        ImageView image = new ImageView(getBaseContext());
//	        TextView text = new TextView(getBaseContext());
//	        image.setImageResource(R.drawable.icon);
//	        image.setImageBitmap(bitmap2);
//	        text.setText("Hello!");
//	        toastLayout.addView(image);
//	        toastLayout.addView(text);
//	        ImageToast.setView(toastLayout);
//	        ImageToast.setDuration(Toast.LENGTH_LONG);
//	        ImageToast.show();
//			dbAdapter.addParcour("Hogeschool Rotterdam", 323, bitmapdata);
//			dbAdapter.addParcourPunten(0, 4.4598376750946045, 51.906194356000775);
//			dbAdapter.addParcourPunten(0, 4.459467530250549, 51.90666100463377);
//			dbAdapter.addParcourPunten(0, 4.459124207496643, 51.90715412451627);
//			dbAdapter.addParcourPunten(0, 4.460046887397766, 51.907283195269386);
//			dbAdapter.addParcourPunten(0, 4.4596123695373535, 51.906948934350375);
//			dbAdapter.addParcourPunten(0, 4.459859132766724, 51.90654517031909);
//			dbAdapter.addParcourPunten(0, 4.46020245552063, 51.90610168761015);

			dbAdapter.addParcour("Rotterdam", 384, bitmapdata);
			dbAdapter.addParcourPunten(0, 4.460256099700928, 51.907279885767515);
			dbAdapter.addParcourPunten(0, 4.459354877471924, 51.90698864864919);
			dbAdapter.addParcourPunten(0, 4.459011554718018, 51.90747845544727);
			dbAdapter.addParcourPunten(0, 4.45871114730835, 51.90784911650056);
			dbAdapter.addParcourPunten(0, 4.45845365524292, 51.908285963100546);
			dbAdapter.addParcourPunten(0, 4.458217620849609, 51.90866985508979);
			dbAdapter.addParcourPunten(0, 4.457917213439941, 51.90906698128081);

		}
		
		dbAdapter.close();
	}
	
	public void onPause(){
		super.onPause();
	}
	
	public void onDestroy(){
		super.onDestroy();
	}

}